package com.lvy.hczn.transmit.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lvy.hczn.front.common.constant.Constants;
import com.lvy.hczn.front.common.constant.MqConstants;
import com.lvy.hczn.front.common.core.domain.AjaxResult;
import com.lvy.hczn.front.common.core.domain.entity.SysDictData;
import com.lvy.hczn.front.common.core.domain.entity.SysUser;
import com.lvy.hczn.front.common.exception.UtilException;
import com.lvy.hczn.front.common.utils.DictUtils;
import com.lvy.hczn.front.system.domain.business.*;
import com.lvy.hczn.front.system.domain.business.dto.*;
import com.lvy.hczn.front.system.domain.system.SysArea;
import com.lvy.hczn.front.system.domain.system.SysOperLog;
import com.lvy.hczn.front.system.service.*;
import com.lvy.hczn.mq.rocket.ParamInfo;
import com.lvy.hczn.transmit.common.ConstantTransmit;
import com.lvy.hczn.transmit.domain.dto.cteck.*;
import com.lvy.hczn.transmit.service.ConsumeService;
import com.lvy.hczn.transmit.service.GoodsBoxService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Slf4j
public class ConsumeServiceImpl implements ConsumeService {

    @Autowired
    private WarehouseService warehouseService;

    @Autowired
    private ISysAreaService sysAreaService;

    @Autowired
    private ISysOperLogService sysOperLogService;

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private GoodsBoxService goodsBoxService;

    @Autowired
    private IParcelService parcelService;

    /**
     * 推送异常处理
     *
     * @param title
     * @param meth
     * @param param
     * @param errorMsg
     * @return void
     * @author yw
     * @date 2023-11-05 20:25:02
     */
    public void initOperLog(String title, String meth, String param, String errorMsg) {
        sysOperLogService.initOperLog(title, meth, param, errorMsg);
    }

    /**
     * 同步表的消息消费业务处理
     *
     * @param message
     * @return
     * @author yw
     * @date 2021-06-28 12:27:12
     */
    @Override
    public void doBusiness(MessageExt message) throws Exception {
        String tag = message.getProperties().get("TAGS");
        String key = message.getProperties().get("KEYS");
        byte[] bt = message.getBody();
        String str = new String(bt, StandardCharsets.UTF_8);
        String topic = message.getTopic();
        log.info("doBusiness:topic:{};tag:{};str:{}", topic, tag, str);

        switch (topic) {
            case MqConstants.TOPIC_CHANGE_FO_WAREHOUSE:
                //仓库表信息同步
                syncWarehouse(topic, key, tag, str);
                break;
            case MqConstants.TOPIC_WAREHOUSE_EMPTY_OUT_ENTRY_BOX:
                //空箱出入库单据，不入货架
                syncEmptyGoodsBoxToPlatform(topic, key, tag, str);
                break;
            case MqConstants.TOPIC_SORT_DONE:
                sortDone(topic, key, tag, str);
                break;
            case MqConstants.TOPIC_ARRIVE:
                //货物到达仓库或配送单-配送员入仓（销售配送）
                arrive(topic, key, tag, str);
                break;
            case MqConstants.TOPIC_TRANSFER_MSG:
                //调拨分拣完成通知
                transferSortDoneMsg(topic, key, tag, str);
                break;
            case MqConstants.TOPIC_NET_WEIGHT:
                netWeight(topic, key, tag, str);
                break;
            default:
                warehouseArea(topic, key, tag, str);
        }
    }

    /**
     * @Description 货箱净重称重更新到数据中心
     * @Param [topic, key, tag, content]
     * @Author yw
     * @Date 2024/4/26 11:11
     * @Return void
     **/
    public void netWeight(String topic, String key, String tag, String content) {
        ParamInfo goodsBoxParamInfo = JSON.parseObject(content, ParamInfo.class);
        GoodsBox goodsBox = JSON.parseObject(JSON.toJSONString(goodsBoxParamInfo.getData()), GoodsBox.class);
        GoodsBox model = goodsBoxService.getOne(Wrappers.<GoodsBox>lambdaQuery().eq(GoodsBox::getBoxCode, goodsBox.getBoxCode()).last("limit 1"));
        boolean result;
        if (model != null) {
            goodsBox.setId(model.getId());
            goodsBoxService.updateById(goodsBox);
        } else {
            goodsBox.setId(null);
            result = goodsBoxService.save(goodsBox);
            /*发送到平台**/
            if (result) {
                List<GoodsBox> goodsBoxListCopy = new ArrayList<>();
                goodsBoxListCopy.add(goodsBox);
                goodsBoxService.sendNewGoodsBoxInfo(goodsBoxListCopy);
            }
        }
    }

    /**
     * 调拨分拣完成通知
     *
     * @param content
     * @return void
     * @author yw
     * @date 2023-07-14 18:11:10
     */
    public void transferSortDoneMsg(String topic, String key, String tag, String content) {
        String urlDelivery = DictUtils.getDictValue(Constants.INTER_TRANSMIT_PLATFORM_SYNC_INFO, Constants.TRANSFER_SORT_DONE_MSG);
        String domain = DictUtils.getDictValue(Constants.PLATFORM_DOMAIN, Constants.PLATFORM_DOMAIN_INTER);
        if (!StrUtil.hasEmpty(urlDelivery, domain)) {
//            TransferSortDone transferSortDone = convertData(content);
            TransferSortDone completeDto = convertTransferSortingDataNew(content);
            String param = JSON.toJSONString(completeDto);
            log.error("transferSortDoneMsgParam：{}", param);
            String codeResult = HttpRequest.post(domain + urlDelivery).body(param).execute().body();
            AjaxResult codeAjaxResult = JSON.parseObject(codeResult, AjaxResult.class);
            log.error("transferSortDoneMsgReturn：{}", JSON.toJSONString(codeAjaxResult));
            if (!String.valueOf(codeAjaxResult.get("isOk")).equals("1")) {
                //todo 异常处理，保存或重新发送
                initOperLog("调拨分拣完成通知推送异常", domain + urlDelivery, param, codeResult);
            }
        } else {
            log.error("调拨分拣完成通知域名或接口地址为空");
        }
    }

    /**
     * 调拨分拣完成推送，推送内容为，整箱，包裹，以及非整箱的商品和包裹信息
     *
     * @Description
     * @Param
     * @Author yw
     * @Date 2025/5/7 11:49
     * @Return
     **/
    public TransferSortDone convertTransferSortingDataNew(String content) {
        TransferSortDone transferSortDone = new TransferSortDone();
        TypeReference<ParamInfo<TransferOrderDto>> typeReference = new TypeReference<>() {
        };
        ParamInfo<TransferOrderDto> paramInfo = JSONUtil.toBean(content, typeReference, true);
        transferSortDone.setTransferCode(paramInfo.getServiceCode());
        transferSortDone.setReqId(paramInfo.getWarehouseCode());
        List<TransferSortDoneDetail> detailList = new ArrayList<>();
        TransferOrderDto transferOrderDto = paramInfo.getData();
        //整箱数据组装
        LinkedHashMap<Integer, List<SortTaskDetail>> sortTaskDetailMap = transferOrderDto.getSortTaskDetailList().stream().collect(Collectors.groupingBy(SortTaskDetail::getDetailType, LinkedHashMap::new, Collectors.toList()));
        transferOrderDto.getGoodsBoxList().forEach(goodsBox -> {
            if (goodsBox.getDetailList() != null && !goodsBox.getDetailList().isEmpty()) {
                TransferSortDoneDetail detail = new TransferSortDoneDetail();
                GoodsBoxDetail goodsBoxDetail = goodsBox.getDetailList().get(0);
                detail.setContainerId(goodsBox.getGoodsBoxSpecId());
                detail.setCartonCode(goodsBox.getBoxCode());
                detail.setCartonWeight(goodsBox.getWeight());
                detail.setMerchandiseCode(goodsBoxDetail.getSpuId());
                detail.setMerchandiseSku(goodsBoxDetail.getSkuCode());
                sortTaskDetailMap.forEach((k, v) -> {
                    if (Constants.SORT_TASK_DETAIL_TYPE_TWO.equals(k)) {
                        v.forEach(sortTaskDetail -> {
                            if (sortTaskDetail.getSpuId().equals(goodsBoxDetail.getSpuId()) && sortTaskDetail.getSkuCode().equals(goodsBoxDetail.getSkuCode())) {
                                int quantity = goodsBox.getWeight().divide(sortTaskDetail.getWeight(), 0, RoundingMode.DOWN).intValue();
                                detail.setTransferTfNum(quantity);
                                detail.setTransferNum(quantity);
                            }
                        });
                    }
                });
                detail.setProducerId(goodsBoxDetail.getProducerId());
                detail.setProducerDate(goodsBoxDetail.getProduceDate());
                detail.setWarrantyDate(goodsBoxDetail.getWarrantyDate());
                if (goodsBox.isFullGoodsBox()) {
                    detail.setFullBox(ConstantTransmit.FULL_BOX_TWO);
                } else {
                    detail.setFullBox(ConstantTransmit.FULL_BOX_ONE);
                }
                detailList.add(detail);
            }
        });


        //包裹数据组装
        List<TransferSortingCompleteParcelsDto> parcelList = new ArrayList<>();
        sortTaskDetailMap.forEach((k, v) -> {
            if (Constants.SORT_TASK_DETAIL_TYPE_THREE.equals(k)) {
                v.forEach(sortTaskDetail -> {
                    TransferSortingCompleteParcelsDto transferSortingCompleteParcelsDto = new TransferSortingCompleteParcelsDto();
                    transferSortingCompleteParcelsDto.setParcelNo(sortTaskDetail.getSaleOrderCode());
                    transferSortingCompleteParcelsDto.setTemperAreaId(sortTaskDetail.getTemperatureId());
                    parcelList.add(transferSortingCompleteParcelsDto);
                });
            } else if (Constants.SORT_TASK_DETAIL_TYPE_TWO.equals(k)) {
                //非整箱商品分拣组装
                v.forEach(sortTaskDetail -> {
                    TransferSortDoneDetail detail = new TransferSortDoneDetail();
                    detail.setCartonWeight(sortTaskDetail.getWeight().multiply(new BigDecimal(sortTaskDetail.getQuantity())));
                    detail.setMerchandiseCode(sortTaskDetail.getSpuId());
                    detail.setMerchandiseSku(sortTaskDetail.getSkuCode());
                    detail.setTransferTfNum(sortTaskDetail.getQuantity());
                    detail.setTransferNum(sortTaskDetail.getQuantity());
                    detail.setFullBox(ConstantTransmit.FULL_BOX_ONE);
                    detailList.add(detail);
                });
            }
        });

        transferSortDone.setParcels(parcelList);
        transferSortDone.setGoods(detailList);
        return transferSortDone;
    }


    public TransferSortingCompleteDto convertTransferSortingData(String content) {
        TypeReference<ParamInfo<WarehousingEntry>> typeReference = new TypeReference<>() {
        };
        ParamInfo<WarehousingEntry> paramInfo = JSONUtil.toBean(content, typeReference, true);

        TransferSortingCompleteDto transferSortingCompleteDto = new TransferSortingCompleteDto();
        transferSortingCompleteDto.setTransferCode(paramInfo.getWarehouseEntryCode());
        transferSortingCompleteDto.setReqId(paramInfo.getWarehouseCode());

        List<TransferSortingCompleteParcelsDto> parcels = new ArrayList<>();
        List<TransferSortingCompleteGoodsDto> goods = new ArrayList<>();

        var warehousingEntrys = paramInfo.getList();

        List<WarehousingEntry> goodsWarehousingEntries = new ArrayList<>();

        String bgPrefix = DictUtils.getDictValue(Constants.SYS_DICT_ORDER_TYPE, Constants.SYS_DICT_ORDER_TYPE_BG);
        warehousingEntrys.forEach(warehousingEntry -> {
            if (warehousingEntry.getSaleOrderDetailId().startsWith("BG")) {
                // 如果是包裹
                TransferSortingCompleteParcelsDto parcelsDto = new TransferSortingCompleteParcelsDto();
                parcelsDto.setParcelNo(warehousingEntry.getSaleOrderDetailId());
                parcelsDto.setSortUser(warehousingEntry.getUpdateBy());
                parcelsDto.setCartonCode(warehousingEntry.getBoxCode());
                parcelsDto.setTemperAreaId(warehousingEntry.getTemperatureZoneCode().toString());

                if (StrUtil.isNotBlank(warehousingEntry.getBatchCode())) {
                    var goodBox = goodsBoxService.getOne(Wrappers.<GoodsBox>lambdaQuery().eq(GoodsBox::getBoxCode, warehousingEntry.getBoxCode()));
                    if (Objects.nonNull(goodBox)) {
                        parcelsDto.setContainerId(goodBox.getGoodsBoxSpecId());
                    }
                }

                return;
            }
            goodsWarehousingEntries.add(warehousingEntry);
        });

        if (CollUtil.isNotEmpty(goodsWarehousingEntries)) {
            Map<LocalDateTime, Map<String, Map<String, List<WarehousingEntry>>>> map = goodsWarehousingEntries.stream()
                    .collect(Collectors.groupingBy(WarehousingEntry::getShelfLife, Collectors.groupingBy(WarehousingEntry::getSkuCode,
                            Collectors.groupingBy(WarehousingEntry::getUpdateBy))));

            map.forEach((k, shelfLifeMap) -> {
                shelfLifeMap.forEach((k1, skuMap) -> {
                    skuMap.forEach((k2, updateByList) -> {
                        var entry = updateByList.get(0);

                        TransferSortingCompleteGoodsDto goodsDto = new TransferSortingCompleteGoodsDto();
                        goodsDto.setCartonCode(entry.getBatchCode());
                        if (StrUtil.isNotBlank(entry.getBatchCode())) {
                            var goodBox = goodsBoxService.getOne(Wrappers.<GoodsBox>lambdaQuery().eq(GoodsBox::getBoxCode, entry.getBoxCode()));
                            if (Objects.nonNull(goodBox)) {
                                goodsDto.setContainerId(goodBox.getGoodsBoxSpecId());
                            }
                        }

                        Integer transferTfNum = 0;
                        BigDecimal cartonWeight = BigDecimal.ZERO;

                        for (WarehousingEntry warehousingEntry : updateByList) {
                            cartonWeight = cartonWeight.add(warehousingEntry.getWeight());
                            transferTfNum = transferTfNum + warehousingEntry.getQuantity();
                        }
                        goodsDto.setCartonWeight(cartonWeight.toEngineeringString());
                        goodsDto.setMerchandiseCode(entry.getSpuId());
                        goodsDto.setMerchandiseSku(entry.getSkuCode());
                        goodsDto.setTransferTfNum(transferTfNum.toString());
                        goodsDto.setTransferNum(transferTfNum.toString());
                        goodsDto.setSortUser(entry.getUpdateBy());
                        goodsDto.setProducerId(entry.getSupplierCode());
                        goodsDto.setProducerDate(entry.getPickTime().toString());
                        goodsDto.setWarrantyDate(entry.getWarrantyDate().toString());
                        goodsDto.setFullBox(entry.getFullBox().toString());
                    });
                });
            });
        }

        transferSortingCompleteDto.setGoods(goods);
        transferSortingCompleteDto.setParcels(parcels);
        return transferSortingCompleteDto;
    }


    /**
     * 调拨单分拣完成返回平台数据转换
     *
     * @param content
     * @return com.lvy.hczn.transmit.domain.dto.cteck.TransferSortDone
     * @author yw
     * @date 2023-08-25 19:48:36
     */
    public TransferSortDone convertData(String content) {
        ParamInfo goodsBoxDetailParamInfo = JSON.parseObject(content, ParamInfo.class);
        TransferSortDone transferSortDone = new TransferSortDone();
        List<GoodsBox> goodsBoxList = JSON.parseArray(JSON.toJSONString(goodsBoxDetailParamInfo.getList()), GoodsBox.class);
        if (goodsBoxList != null && goodsBoxList.size() > 0) {
            transferSortDone.setTransferCode(goodsBoxList.get(0).getOutboundOrderCode());
            transferSortDone.setReqId(goodsBoxDetailParamInfo.getWarehouseCode());
            List<TransferSortDoneDetail> transferSortDoneDetailList = new ArrayList<>();
            goodsBoxList.forEach(goodsBox -> {
                List<GoodsBoxDetail> goodsBoxDetailList = JSON.parseArray(JSON.toJSONString(goodsBox.getDetailList()), GoodsBoxDetail.class);
                goodsBoxDetailList.forEach(goodsBoxDetail -> {
                    TransferSortDoneDetail transferSortDoneDetail = new TransferSortDoneDetail();
                    transferSortDoneDetail.setCartonCode(goodsBoxDetail.getBoxCode());
                    transferSortDoneDetail.setContainerId(goodsBox.getGoodsBoxSpecId());
                    transferSortDoneDetail.setCartonWeight(goodsBoxDetail.getWeight());
                    transferSortDoneDetail.setTransferTfNum(goodsBoxDetail.getQuantity());
                    transferSortDoneDetail.setTransferNum(goodsBoxDetail.getQuantity());
                    transferSortDoneDetail.setMerchandiseCode(goodsBoxDetail.getSpuCode());
                    transferSortDoneDetail.setMerchandiseSku(goodsBoxDetail.getSkuCode());
                    transferSortDoneDetail.setSortUser(goodsBoxDetail.getUpdateBy());
                    transferSortDoneDetail.setProducerId(goodsBoxDetail.getProducerId());
                    transferSortDoneDetail.setWarrantyDate(goodsBoxDetail.getWarrantyDate());
                    transferSortDoneDetail.setProducerDate(goodsBoxDetail.getProduceDate());
                    transferSortDoneDetailList.add(transferSortDoneDetail);
                });
            });
            transferSortDone.setGoods(transferSortDoneDetailList);
        }
        return transferSortDone;
    }

    /**
     * 货物到达仓库或配送单-配送员入仓（销售配送）
     *
     * @param topic
     * @param key
     * @param tag
     * @param content
     * @return void
     * @author yw
     * @date 2023-07-14 18:19:02
     */
    public void arrive(String topic, String key, String tag, String content) {
        log.error("arrive：{},{}", tag, content);
        switch (tag) {
            case MqConstants.TOPIC_ARRIVE_TAG_DELIVERY_CLERK:
                //配送单-配送员入仓,适用于销售配送
                arriveDeliveryClerk(content);
                break;
            case MqConstants.TOPIC_ARRIVE_TAG_GOODS_ENTRY_FH:
                //发货配送，供应商自配，不走配送单流程
                arriveGoodsInvoice(content);
                break;
            case MqConstants.TOPIC_ARRIVE_TAG_GOODS_ENTRY_FH_ENTRY:
                //发货单入仓通知
                arriveGoodsEntry(content);
                break;
            case MqConstants.TOPIC_ARRIVE_TAG_GOODS_ENTRY_PS:
                //配送单-货物入仓通知，适用于发货配送，退货配送，拒收配送
                arriveGoodsDelivery(content);
                break;
            case MqConstants.TOPIC_ARRIVE_TAG_GOODS_ENTRY_YD:
                //运输单到达通知
                transportMsg(content);
                break;
            case MqConstants.TOPIC_ARRIVE_TAG_PARCEL_ENTRY:
                // 包裹到达通知
                arriveParcelEntry(content);
                break;
            default:
                break;
        }
    }

    /**
     * 运输单送达后通知平台
     * 配送单-配送员入仓,适用于销售配送
     *
     * @param content
     * @return void
     * @author yw
     * @date 2023-07-14 18:11:10
     */
    public void transportMsg(String content) {
        String urlDelivery = DictUtils.getDictValue(Constants.INTER_TRANSMIT_PLATFORM_SYNC_INFO, Constants.INTER_ARRIVE_TRANSPORT_MSG);
        String domain = DictUtils.getDictValue(Constants.PLATFORM_DOMAIN, Constants.PLATFORM_DOMAIN_INTER);
        if (!StrUtil.hasEmpty(urlDelivery, domain)) {
            String codeResult = HttpRequest.post(domain + urlDelivery).body(content).execute().body();
            AjaxResult codeAjaxResult = JSONUtil.toBean(codeResult, AjaxResult.class);
            log.error("transportMsgReturn：" + JSONUtil.toJsonStr(codeAjaxResult));
            if (!String.valueOf(codeAjaxResult.get("isOk")).equals("1")) {
                initOperLog("运输单送到达仓库推送异常", domain + urlDelivery, content, codeResult);
            }
        } else {
            log.error("运输单送到达仓库域名或接口地址为空");
        }
    }

    /**
     * 到达仓库通知平台
     * 配送单-配送员入仓,适用于销售配送
     *
     * @param content
     * @return void
     * @author yw
     * @date 2023-07-14 18:11:10
     */
    public void arriveDeliveryClerk(String content) {
        String urlDelivery = DictUtils.getDictValue(Constants.INTER_TRANSMIT_PLATFORM_SYNC_INFO, Constants.INTER_ARRIVE_DELIVERY_CLERK);
        String domain = DictUtils.getDictValue(Constants.PLATFORM_DOMAIN, Constants.PLATFORM_DOMAIN_INTER);
        if (!StrUtil.hasEmpty(urlDelivery, domain)) {
            String codeResult = HttpRequest.post(domain + urlDelivery).body(content).execute().body();
            AjaxResult codeAjaxResult = JSONUtil.toBean(codeResult, AjaxResult.class);
            log.error("arriveDeliveryClerk配送到达仓库同步到平台返回：" + JSONUtil.toJsonStr(codeAjaxResult));
            if (!String.valueOf(codeAjaxResult.get("isOk")).equals("1")) {
                //todo 异常处理，保存或重新发送
                initOperLog("配送到达仓库推送异常", domain + urlDelivery, content, codeResult);
            }
        } else {
            log.error("销售配送到达仓库域名或接口地址为空");
        }
    }

    /**
     * 到达仓库通知
     * <p>
     * 发货配送，供应商自配，不走配送单流程接口
     *
     * @param content
     * @return void
     * @author yw
     * @date 2023-07-14 18:13:59
     */
    public void arriveGoodsInvoice(String content) {
        //发货配送，供应商自配，不走配送单流程接口
        String urlDelivery = DictUtils.getDictValue(Constants.INTER_TRANSMIT_PLATFORM_SYNC_INFO, Constants.INTER_ARRIVE_GOODS_ENTRY_FH);
        String domain = DictUtils.getDictValue(Constants.PLATFORM_DOMAIN, Constants.PLATFORM_DOMAIN_INTER);
        if (!StrUtil.hasEmpty(urlDelivery, domain)) {
            Map<String, Object> map = JSON.parseObject(content, Map.class);
            String codeResult = HttpRequest.post(domain + urlDelivery).form(map).execute().body();
            AjaxResult codeAjaxResult = JSONUtil.toBean(codeResult, AjaxResult.class);
            log.error("arriveGoodsInvoice供应商自配到达仓库同步到平台返回：" + JSONUtil.toJsonStr(codeAjaxResult));
            if (!String.valueOf(codeAjaxResult.get("isOk")).equals("1")) {
                //todo 异常处理，保存或重新发送
                initOperLog("供应商自配到达仓库推送异常", domain + urlDelivery, JSON.toJSONString(map), codeResult);
            }
        } else {
            log.error("供应商自配到达仓库域名或接口地址为空");
        }
    }

    /**
     * 到达仓库通知
     * <p>
     * 通用发货入仓通知平台
     *
     * @param content
     * @return void
     * @author yw
     * @date 2023-07-14 18:13:59
     */
    public void arriveGoodsEntry(String content) {
        //发货配送，供应商自配，不走配送单流程接口
        String urlDelivery = DictUtils.getDictValue(Constants.INTER_TRANSMIT_PLATFORM_SYNC_INFO, Constants.INTER_ARRIVE_GOODS_ENTRY_FH_ALL);
        String domain = DictUtils.getDictValue(Constants.PLATFORM_DOMAIN, Constants.PLATFORM_DOMAIN_INTER);
        if (!StrUtil.hasEmpty(urlDelivery, domain)) {
            String codeResult = HttpRequest.post(domain + urlDelivery).body(content).execute().body();
            AjaxResult codeAjaxResult = JSONUtil.toBean(codeResult, AjaxResult.class);
            log.error("arriveGoodsEntry通用发货入仓通知平台返回：" + JSONUtil.toJsonStr(codeAjaxResult));
            if (!String.valueOf(codeAjaxResult.get("isOk")).equals("1")) {
                //todo 异常处理，保存或重新发送
                initOperLog("通用发货入仓通知平台返回异常", domain + urlDelivery, content, codeResult);
            }
        } else {
            log.error("通用发货入仓通知平台域名或接口地址为空");
        }
    }

    /**
     * 包裹到达仓库通知
     * <p>
     * 通用发货入仓通知平台
     *
     * @param content
     * @return void
     * @author yw
     * @date 2023-07-14 18:13:59
     */
    public void arriveParcelEntry(String content) {
        //发货配送，供应商自配，不走配送单流程接口  /CloudShopCenter-manager/api/putOutStorage
        String urlParcel = DictUtils.getDictValue(Constants.INTER_TRANSMIT_PLATFORM_SYNC_INFO, Constants.INTER_ARRIVE_PARCEL_ENTRY);
        String domain = DictUtils.getDictValue(Constants.PLATFORM_DOMAIN, Constants.PLATFORM_DOMAIN_INTER);
        if (!StrUtil.hasEmpty(urlParcel, domain)) {
//            TypeReference<WarehouseParcelDto> reference = new TypeReference<>() {};
//            WarehouseParcelDto parcelDto = JSONUtil.toBean(content,reference,false);
//            var param = JSONUtil.toJsonStr(parcelDto);
            String url = domain + urlParcel;
            log.error("url:{},arriveParcelEntry包裹参数:{}",url,content);
//            String codeResult = HttpUtil.post(url, content);
            String codeResult = HttpRequest.post(url).body(content).execute().body();
            AjaxResult codeAjaxResult = JSONUtil.toBean(codeResult, AjaxResult.class);
            log.error("arriveParcelEntry通用包裹出入库通知平台返回：" + codeResult);
            if (!String.valueOf(codeAjaxResult.get("isOk")).equals("1")) {
                //todo 异常处理，保存或重新发送
                initOperLog("通用包裹出入库通知平台返回异常", url, content, codeResult);
            }
        } else {
            log.error("通用包裹出入库通知平台域名或接口地址为空");
        }
    }



    /**
     * 到达仓库通知
     * <p>
     * 配送单-货物入仓通知，适用于发货配送，退货配送，拒收配送
     *
     * @param content
     * @return void
     * @author yw
     * @date 2023-07-14 18:13:59
     */
    public void arriveGoodsDelivery(String content) {
        String urlDelivery = DictUtils.getDictValue(Constants.INTER_TRANSMIT_PLATFORM_SYNC_INFO, Constants.INTER_ARRIVE_GOODS_ENTRY_PS);
        String domain = DictUtils.getDictValue(Constants.PLATFORM_DOMAIN, Constants.PLATFORM_DOMAIN_INTER);
        if (!StrUtil.hasEmpty(urlDelivery, domain)) {
            String codeResult = HttpRequest.post(domain + urlDelivery).body(content).execute().body();
            AjaxResult codeAjaxResult = JSONUtil.toBean(codeResult, AjaxResult.class);
            log.error("arriveGoodsDelivery货物到达仓库同步到平台返回：" + JSONUtil.toJsonStr(codeAjaxResult));
            if (!String.valueOf(codeAjaxResult.get("isOk")).equals("1")) {
                //todo 异常处理，保存或重新发送
                initOperLog("货物到达仓库推送异常", domain + urlDelivery, content, codeResult);
                throw new UtilException("仓库空箱出入库单据推送异常：" + content);
            }
        } else {
            log.error("货物到达仓库域名或接口地址为空");
        }
    }

    /**
     * 分拣完成，发送到平台，更新库存和配送员信息展示取货位置
     *
     * @param topic
     * @param key
     * @param tag
     * @param content
     * @return void
     * @author yw
     * @date 2023-06-27 09:57:09
     */
    public void sortDone(String topic, String key, String tag, String content) {
        SortDone sortDone = new SortDone();
        convertSortDone(content, sortDone);
        String param = JSON.toJSONString(sortDone);
        log.error("sortDone分拣完成通知：{}", param);
        //更新到配送端
        String urlDelivery = DictUtils.getDictValue(Constants.INTER_TRANSMIT_PLATFORM_SYNC_INFO, Constants.WAREHOUSE_SALE_OUT_DELIVERY);
        String domain = DictUtils.getDictValue(Constants.PLATFORM_DOMAIN, Constants.PLATFORM_DOMAIN_INTER);
        if (!StrUtil.hasEmpty(urlDelivery, domain)) {
            String codeResult = HttpRequest.post(domain + urlDelivery).body(param).execute().body();
            AjaxResult codeAjaxResult = JSONUtil.toBean(codeResult, AjaxResult.class);
            log.error("更新到配送端推送sortDoneReturn：" + JSONUtil.toJsonStr(codeAjaxResult));
            if (!String.valueOf(codeAjaxResult.get("isOk")).equals("1")) {
                //todo 异常处理，保存或重新发送
                initOperLog("sortDone分拣完成更新到配送端推送异常", domain + urlDelivery, param, codeResult);
            }
            //更新到平台库存
            /*String urlStock = DictUtils.getDictValue(Constants.INTER_TRANSMIT_PLATFORM_SYNC_INFO, Constants.WAREHOUSE_SALE_OUT_STOCK);
            if (!StrUtil.isEmpty(urlStock)) {
                String result = HttpRequest.post(domain + urlStock).body(content).execute().body();
                AjaxResult stockResult = JSONUtil.toBean(result, AjaxResult.class);
                log.error("更新到平台库存同步到平台返回：" + JSONUtil.toJsonStr(stockResult));
                if (!String.valueOf(stockResult.get("isOk")).equals("1")) {
                    //todo 异常处理，保存或重新发送
                    log.error("更新到平台库存推送异常");
                }
            }*/
        } else {
            log.error("销售出库域名或接口地址为空");
        }
    }

    /**
     * 配送单-分拣任务完成通知,适用于销售配送
     *
     * @param content
     * @param sortDone
     * @return void
     * @author yw
     * @date 2023-07-25 15:46:45
     */
    public void convertSortDone(String content, SortDone sortDone) {
        ParamInfo<SortTask> info = JSONUtil.toBean(content, ParamInfo.class);
        SortTask sortTask = JSONUtil.toBean(JSONUtil.toJsonStr(info.getData()), SortTask.class);
        if (sortTask != null) {
            if (sortTask.getList() != null && !sortTask.getList().isEmpty()) {
                List<SortTaskDetail> sortTaskDetailList = sortTask.getList();

                //单号
                sortDone.setDeliveryCode(sortTask.getOutboundOrderCode());
                //货位(去重)
                String shelfLocation = sortTaskDetailList.stream().map(SortTaskDetail::getShelfLocation).distinct().collect(Collectors.joining(","));
                sortDone.setGoodLocal(shelfLocation);
                //实际分拣数量
                Integer sortQuantity = sortTaskDetailList.stream().mapToInt(SortTaskDetail::getSortQuantity).sum();
                sortDone.setTotalNum(sortQuantity);
                //总重量
                BigDecimal sortWeight = sortTaskDetailList.stream().map(SortTaskDetail::getSortWeight).reduce(BigDecimal.ZERO, BigDecimal::add);
                sortDone.setTotalWeight(sortWeight);

                /**包装袋**/
                //包装袋分组
                LinkedHashMap<String, List<SortTaskDetail>> map = sortTaskDetailList.stream().filter(model -> !StrUtil.isEmpty(model.getPackId())).collect(Collectors.groupingBy(SortTaskDetail::getPackId, LinkedHashMap::new, Collectors.toList()));
                List<TPack> tPackList = new ArrayList<>();
                //分拣完成使用的不同规格包装袋数量
                map.forEach((k, v) -> {
                    TPack tPack = new TPack();
                    Integer packQuantity = sortTaskDetailList.stream().mapToInt(SortTaskDetail::getSortQuantity).sum();
                    tPack.setBagId(k);
//                    tPack.setBagNum(packQuantity);
                    tPack.setBagNum(v.size());
                    tPackList.add(tPack);
                });
                sortDone.setBagList(tPackList);

                List<SortDoneDetail> sortDoneDetails = new ArrayList<>();
                sortTaskDetailList.forEach(sortTaskDetail -> {
                    SortDoneDetail sortDoneDetail = new SortDoneDetail();
                    sortDoneDetail.setMerchandiseCode(sortTaskDetail.getSpuCode());
                    sortDoneDetail.setMerchandiseSku(sortTaskDetail.getSkuCode());
                    /*平台根据实际反馈重量退差价，所以数量只能是返回的购买数量，而不是分拣数量**/
                    sortDoneDetail.setMerchandiseNum(sortTaskDetail.getQuantity());
                    if (sortTaskDetail.getStandard() != null && sortTaskDetail.getStandard() == 1) {
                        sortDoneDetail.setMerchandiseWeight(sortTaskDetail.getWeight().multiply(BigDecimal.valueOf(sortTaskDetail.getSortQuantity())));
                        sortDoneDetail.setDifferWeight(BigDecimal.ZERO);
                    } else {
                        sortDoneDetail.setMerchandiseWeight(sortTaskDetail.getSortWeight());
                        sortDoneDetail.setDifferWeight(sortTaskDetail.getWeight().multiply(new BigDecimal(sortTaskDetail.getQuantity())).subtract(sortTaskDetail.getSortWeight()).setScale(2, RoundingMode.HALF_UP));
                    }
                    sortDoneDetail.setProducerId(sortTaskDetail.getProducerId());
                    sortDoneDetail.setSortFee(BigDecimal.ZERO);
                    sortDoneDetail.setSortUser(sortTaskDetail.getUpdateBy());
                    sortDoneDetail.setProducerDate(new Date());
                    sortDoneDetail.setWarrantyDate(String.valueOf(RandomUtil.randomInt()));
                    sortDoneDetails.add(sortDoneDetail);
                });
                sortDone.setList(sortDoneDetails);
            }
        }
    }

    /**
     * 空箱入库（不入仓库货架），告知平台
     *
     * @param topic
     * @param key
     * @param tag
     * @param content
     * @return void
     * @author yw
     * @date 2023-06-02 17:50:14
     */
    public void syncEmptyGoodsBoxToPlatform(String topic, String key, String tag, String content) {
        String url = DictUtils.getDictValue(Constants.INTER_TRANSMIT_PLATFORM_SYNC_INFO, Constants.INTER_TRANSMIT_WAREHOUSE_BOX_ENTRY);
        String domain = DictUtils.getDictValue(Constants.PLATFORM_DOMAIN, Constants.PLATFORM_DOMAIN_INTER);
        if (StrUtil.hasEmpty(url, domain)) {
            throw new UtilException("空箱入库域名或接口地址为空");
        }
        ParamInfo<WarehouseBoxEntry> info = JSONUtil.toBean(content, ParamInfo.class);
        if (info.getData() != null) {
            WarehouseBoxEntry warehouseBoxEntry = JSON.parseObject(JSON.toJSONString(info.getData()), WarehouseBoxEntry.class);
            BoxEmpty boxEmpty = new BoxEmpty();
            List<BoxEmptyDetail> boxEmptyDetails = new ArrayList<>();
            initBoxEmpty(warehouseBoxEntry, boxEmpty, boxEmptyDetails);
            boxEmpty.setDetails(boxEmptyDetails);
            sendBoxEntry(url, domain, JSON.toJSONString(boxEmpty));
        } else if (info.getList() != null && !info.getList().isEmpty()) {
            //不确定平台那边啥情况，暂时根据分组来推送
            List<WarehouseBoxEntry> entryList = JSON.parseArray(JSON.toJSONString(info.getList()), WarehouseBoxEntry.class);
            LinkedHashMap<String, List<WarehouseBoxEntry>> entryCodeMap = entryList.stream().collect(Collectors.groupingBy(WarehouseBoxEntry::getBoxEntryCode, LinkedHashMap::new, Collectors.toList()));
            entryCodeMap.forEach((mapKey, value) -> {
                LinkedHashMap<Integer, List<WarehouseBoxEntry>> typeMap = value.stream().collect(Collectors.groupingBy(WarehouseBoxEntry::getType, LinkedHashMap::new, Collectors.toList()));
                typeMap.forEach((k, v) -> {
                    LinkedHashMap<Integer, List<WarehouseBoxEntry>> overTypeMap = v.stream().collect(Collectors.groupingBy(WarehouseBoxEntry::getOverType, LinkedHashMap::new, Collectors.toList()));
                    overTypeMap.forEach((overTypeKey, overTypeValue) -> {
                        BoxEmpty boxEmpty = new BoxEmpty();
                        List<BoxEmptyDetail> boxEmptyDetails = new ArrayList<>();
                        overTypeValue.forEach(warehouseBoxEntry -> {
                            initBoxEmpty(warehouseBoxEntry, boxEmpty, boxEmptyDetails);
                        });
                        boxEmpty.setDetails(boxEmptyDetails);
                        sendBoxEntry(url, domain, JSON.toJSONString(boxEmpty));
                    });
                });
            });
        }
    }

    /**
     * 货箱生产商生产货箱同步
     *
     * @param content
     * @return
     * @author yw
     * @date 2023-12-16 16:55:03
     */
    @Override
    public void syncEmptyBox(String content) {
        if (!StrUtil.isEmpty(content)) {
            syncEmptyGoodsBoxToPlatform("", "", "", content);
        }
    }

    /**
     * 初始化推送到平台的数据
     *
     * @param warehouseBoxEntry
     * @param boxEmpty
     * @author yw
     * @date 2023-11-24 20:03:18
     */
    private void initBoxEmpty(WarehouseBoxEntry warehouseBoxEntry, BoxEmpty boxEmpty, List<BoxEmptyDetail> boxEmptyDetails) {
        boxEmpty.setRepId(warehouseBoxEntry.getWarehouseCode());
        boxEmpty.setServiceType(warehouseBoxEntry.getType());
        boxEmpty.setOrderType(warehouseBoxEntry.getType());
        boxEmpty.setOverType(warehouseBoxEntry.getOverType());
        boxEmpty.setServiceCode(warehouseBoxEntry.getBoxEntryCode());
        boxEmpty.setCreateBy(warehouseBoxEntry.getCreateBy());
        BoxEmptyDetail boxEmptyDetail = new BoxEmptyDetail();
        boxEmptyDetail.setContainerCode(warehouseBoxEntry.getBoxCode());
        boxEmptyDetail.setContainerInfoId(warehouseBoxEntry.getGoodsBoxSpecCode());
        SysUser sysUser = sysUserService.selectUserByLoginName(warehouseBoxEntry.getBoxProducer());
        if (sysUser == null) {
            boxEmptyDetail.setBoxManufactureId("1");
        } else {
            boxEmptyDetail.setBoxManufactureId(String.valueOf(sysUser.getUserId()));
        }
        boxEmptyDetails.add(boxEmptyDetail);
    }

    /**
     * 空箱数据推送到平台
     *
     * @param url
     * @param domain
     * @param param
     * @return void
     * @author yw
     * @date 2023-11-24 19:55:41
     */
    private void sendBoxEntry(String url, String domain, String param) {
        log.error("空箱出入库参数传递：{}", param);
        String codeResult = HttpRequest.post(domain + url).body(param).execute().body();
        AjaxResult codeAjaxResult = JSONUtil.toBean(codeResult, AjaxResult.class);
        log.error("仓库空箱出入库单据同步到平台返回：{}", JSONUtil.toJsonStr(codeAjaxResult));
        if (!String.valueOf(codeAjaxResult.get("isOk")).equals("1")) {
            //todo 异常处理，保存或重新发送
            initOperLog("仓库空箱出入库单据推送异常", domain + url, param, codeResult);
            throw new UtilException("仓库空箱出入库单据推送异常：" + param);
        } else {
            initOperLog("仓库空箱出入库单据推送成功", domain + url, param, codeResult);
        }
    }

    /**
     * 运营区域下的tag区分
     *
     * @param topic
     * @param key
     * @param tag
     * @param content
     * @return void
     * @author yw
     * @date 2023-05-29 17:48:07
     */
    public void warehouseArea(String topic, String key, String tag, String content) {
        //走default，区分下topic
//        if (topic.startsWith(MqConstants.TOPIC_WAREHOUSE_AREA)) {
        if (MqConstants.TAG_WAREHOUSE_ENTRY.equals(tag)) {
            //仓库返回入库单到平台
            warehouseEntry(content);
        } else if (MqConstants.TAG_WAREHOUSE_OUT.equals(tag)) {
            //仓库返回出库单到平台
            warehouseOut(content);
        } else if (MqConstants.TOPIC_WAREHOUSE_FRMLOST_TAG.equals(tag)) {
            frmLostRelegateToPlatform(topic, key, tag, content);
        } else if (MqConstants.TAG_WAREHOUSE_SHELF_LOCATION.equals(tag)) {
            shelfLocation(topic, key, tag, content);
        }
//        }
    }

    /**
     * 仓库出入库库位调整推送
     *
     * @param topic
     * @param key
     * @param tag
     * @param content
     * @return void
     * @author yw
     * @date 2023-09-27 12:13:18
     */
    public void shelfLocation(String topic, String key, String tag, String content) {

        String url = DictUtils.getDictValue(Constants.INTER_TRANSMIT_PLATFORM_SYNC_INFO, Constants.INTER_TRANSMIT_SHELF_LOCATION);
        String domain = DictUtils.getDictValue(Constants.PLATFORM_DOMAIN, Constants.PLATFORM_DOMAIN_INTER);
        if (StrUtil.hasEmpty(url, domain)) {
            throw new UtilException("仓库出入库库位调整推送域名或接口地址为空");
        }
        log.error("库位调整参数：" + content);
        String codeResult = HttpRequest.post(domain + url).body(content).execute().body();
        AjaxResult codeAjaxResult = JSONUtil.toBean(codeResult, AjaxResult.class);
        log.error("shelfLocation仓库出入库库位调整推送到平台返回：" + JSONUtil.toJsonStr(codeAjaxResult));
        if (!String.valueOf(codeAjaxResult.get("isOk")).equals("1")) {
            //todo 异常处理，保存或重新发送
            initOperLog("仓库出入库库位调整推送到平台返回异常", domain + url, content, codeResult);
            throw new UtilException("仓库出入库库位调整推送到平台返回异常：" + content);
        } else {
            initOperLog("仓库出入库库位调整推送到平台返回成功", domain + url, content, codeResult);
        }
    }

    /**
     * 报损/降级同步到平台
     *
     * @param topic
     * @param key
     * @param tag
     * @param content
     * @return void
     * @author yw
     * @date 2023-06-04 14:26:17
     */
    public void frmLostRelegateToPlatform(String topic, String key, String tag, String content) {
        //入库单
        String url = DictUtils.getDictValue(Constants.INTER_TRANSMIT_PLATFORM_SYNC_INFO, Constants.INTER_TRANSMIT_FRMLOST_RELEGATE);
        String domain = DictUtils.getDictValue(Constants.PLATFORM_DOMAIN, Constants.PLATFORM_DOMAIN_INTER);
        if (StrUtil.hasEmpty(url, domain)) {
            throw new UtilException("报损/降级域名或接口地址为空");
        }
        String codeResult = HttpRequest.post(domain + url).body(content).execute().body();
        AjaxResult codeAjaxResult = JSONUtil.toBean(codeResult, AjaxResult.class);
        log.error("frmLostRelegateToPlatform仓库报损/降级同步到平台返回：" + JSONUtil.toJsonStr(codeAjaxResult));
        if (!String.valueOf(codeAjaxResult.get("isOk")).equals("1")) {
            //todo 异常处理，保存或重新发送
            initOperLog("仓库报损/降级推送异常", domain + url, content, codeResult);
        }
    }

    /**
     * 入库单
     *
     * @param content
     * @return void
     * @author yw
     * @date 2023-05-29 17:49:20
     */
    public void warehouseEntry(String content) {
        //入库单
        String url = DictUtils.getDictValue(Constants.INTER_TRANSMIT_PLATFORM_SYNC_INFO, Constants.INTER_TRANSMIT_WAREHOUSE_ENTRY);
        String domain = DictUtils.getDictValue(Constants.PLATFORM_DOMAIN, Constants.PLATFORM_DOMAIN_INTER);
        if (StrUtil.hasEmpty(url, domain)) {
            throw new UtilException("入库单域名或接口地址为空");
        }
        ParamInfo<WarehousingEntryDto> info = JSONUtil.toBean(content, ParamInfo.class);
        if (info.getList() != null && !info.getList().isEmpty()) {
            log.error("warehouseEntryParam：{}", content);
            List<WarehousingEntryDto> list = JSONUtil.toList(JSONUtil.toJsonStr(info.getList()), WarehousingEntryDto.class);
            /*根据批次编号分组推送**/
            LinkedHashMap<String, List<WarehousingEntryDto>> map = list.stream().collect(Collectors.groupingBy(WarehousingEntryDto::getBatchCode, LinkedHashMap::new, Collectors.toList()));
            map.forEach((key, value) -> {
                info.setList(value);
                String contentInfo = JSONUtil.toJsonStr(info);
                log.error("warehouseEntryParam分组：{}", contentInfo);
                String codeResult = HttpRequest.post(domain + url).body(contentInfo).execute().body();
                AjaxResult codeAjaxResult = JSONUtil.toBean(codeResult, AjaxResult.class);
                log.error("warehouseEntry仓库入库单同步到平台返回：{}", JSONUtil.toJsonStr(codeAjaxResult));
                if (!String.valueOf(codeAjaxResult.get("isOk")).equals("1")) {
                    //todo 异常处理，保存或重新发送
                    initOperLog("仓库入库单推送异常", domain + url, contentInfo, codeResult);
                    throw new UtilException("仓库入库单推送异常：" + contentInfo);
                } else {
                    initOperLog("仓库入库单推送成功", domain + url, contentInfo, codeResult);
                }
            });
        }
    }

    /**
     * 出库单
     *
     * @param content
     * @return void
     * @author yw
     * @date 2023-05-29 17:49:20
     */
    public void warehouseOut(String content) {
        //入库单
        String url = DictUtils.getDictValue(Constants.INTER_TRANSMIT_PLATFORM_SYNC_INFO, Constants.INTER_TRANSMIT_WAREHOUSE_OUT);
        String domain = DictUtils.getDictValue(Constants.PLATFORM_DOMAIN, Constants.PLATFORM_DOMAIN_INTER);
        if (StrUtil.hasEmpty(url, domain)) {
            throw new UtilException("出库单域名或接口地址为空");
        }
        String codeResult = HttpRequest.post(domain + url).body(content).execute().body();
        AjaxResult codeAjaxResult = JSONUtil.toBean(codeResult, AjaxResult.class);
        log.error("warehouseOut仓库出库单同步到平台返回：" + JSONUtil.toJsonStr(codeAjaxResult));
        if (!String.valueOf(codeAjaxResult.get("isOk")).equals("1")) {
            //todo 异常处理，保存或重新发送
            initOperLog("仓库出库单推送异常", domain + url, content, codeResult);
            throw new UtilException("仓库出库单推送异常：" + content);
        } else {
            initOperLog("仓库出库单推送成功", domain + url, content, codeResult);
        }
    }

    /**
     * 仓库信息转发
     *
     * @param topic
     * @param key
     * @param tag
     * @param content
     * @return void
     * @author yw
     * @date 2023-05-16 11:24:53
     */
    public void syncWarehouse(String topic, String key, String tag, String content) {
        ParamInfo<Warehouse> paramInfo = JSONUtil.toBean(content, ParamInfo.class);
        //todo http转发到平台
        if (paramInfo != null && paramInfo.getData() != null) {
            log.info("syncWarehouse：{}", JSONUtil.toJsonStr(paramInfo));
            /**仓库信息**/
            Warehouse warehouse = JSONUtil.toBean(JSONUtil.toJsonStr(paramInfo.getData()), Warehouse.class);
            ThreadUtil.execAsync(() -> {
                warehouseService.saveOrUpdate(warehouse);
            });
            RepositoryInfo repositoryInfo = new RepositoryInfo();
            repositoryInfo.setRepId(warehouse.getWarehouseCode());
            repositoryInfo.setRepName(warehouse.getWarehouseName());
            repositoryInfo.setRepContact(warehouse.getName());
            repositoryInfo.setMobile(warehouse.getPhone());
            String type = warehouse.getType();
            if (Constants.WAREHOUSE_TYPE_WMS_FRONT.equals(type)) {
                repositoryInfo.setRepType(1);
            } else {
                repositoryInfo.setRepType(2);
            }

            repositoryInfo.setTotalStorageCount(warehouse.getTotalStorageCount());
            repositoryInfo.setProvince(warehouse.getProvinceId());
            repositoryInfo.setCity(warehouse.getCityId());
            repositoryInfo.setDistrict(warehouse.getAreaId());
            repositoryInfo.setRepAddress(warehouse.getAddress());
            repositoryInfo.setLatitude(warehouse.getLatitude());
            repositoryInfo.setLongitude(warehouse.getLongitude());
            repositoryInfo.setAssociationRepId(warehouse.getParentCode());

            /**温区信息**/
            List<RepTemperArea> list = new ArrayList<>();
            if (warehouse.getList() != null) {
                warehouse.getList().forEach(item -> {
                    RepTemperArea area = new RepTemperArea();
                    //第一次仓库新建同步时，firstSync默认false
                    if (!item.isSubtract()) {
                        area.setStorageType(1);
                    } else {
                        area.setStorageType(2);
                    }
                    area.setTemperAreaId(item.getId());
                    area.setTemperAreaVolume(item.getTemperAreaVolume());
                    area.setRepId(warehouse.getWarehouseCode());
                    list.add(area);
                });

                repositoryInfo.setRepTemperAreaList(list);

                //仓库信息接口推送
                String url = DictUtils.getDictValue(Constants.INTER_TRANSMIT_PLATFORM_SYNC_INFO, Constants.INTER_TRANSMIT_WAREHOUSE_URL);
                String domain = DictUtils.getDictValue(Constants.PLATFORM_DOMAIN, Constants.PLATFORM_DOMAIN_INTER);
                if (StrUtil.hasEmpty(url, domain)) {
                    throw new UtilException("仓库信息域名或接口地址为空");
                }
                String regionName = "";

                //数据库暂时不支持mysql8，暂时这样
                SysArea sysAreaPro = sysAreaService.getById(warehouse.getProvinceId());
                SysArea sysAreaCity = sysAreaService.getById(warehouse.getCityId());
                SysArea sysArea = sysAreaService.getById(warehouse.getAreaId());
                if (sysAreaPro != null) {
                    regionName += sysAreaPro.getExtName() + " ";
                }
                if (sysAreaCity != null) {
                    regionName += sysAreaCity.getExtName() + " ";
                }
                if (sysArea != null) {
                    regionName += sysArea.getExtName();
                }

                repositoryInfo.setRegionName(StrUtil.trimEnd(regionName));
                List<RepositoryInfo> repositoryInfoList = new ArrayList<>();
                repositoryInfoList.add(repositoryInfo);
                String str = JSONUtil.toJsonStr(repositoryInfoList);
                log.error("syncWarehouse仓库同步到平台：{}", str);
                String codeResult = HttpRequest.post(domain + url).body(str).execute().body();
                AjaxResult codeAjaxResult = JSONUtil.toBean(codeResult, AjaxResult.class);
                log.error("仓库同步到平台返回：" + JSONUtil.toJsonStr(codeAjaxResult));
                if (!String.valueOf(codeAjaxResult.get("isOk")).equals("1")) {
                    initOperLog("仓库同步到平台异常返回", domain + url, str, codeResult);
                }
            } else {
                log.error("温区列表为空");
            }
        }
    }

    /**
     * 商品同步
     *
     * @param str
     * @param message
     * @return void
     * @author yw
     * @date 2023-05-04 15:13:25
     */
    public void syncSpu(String str, MessageExt message) {
        ParamInfo<Spu> paramInfo = JSONUtil.toBean(str, ParamInfo.class);
        Spu spu = paramInfo.getData();
    }
}
